#define  _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct treenode {
    int data;
    struct treenode* left;
    struct treenode* right;
};
typedef struct treenode treenode;
struct treenode* troot;
treenode* build() {
    int a;
    scanf("%d", &a);
    if (a == 0) return NULL;
    treenode*root = (treenode*)malloc(sizeof(treenode));
    root->data = a;
    root->left = build();
    root->right = build();
    return root;
}

void preorder(treenode* root) {
    if (root == NULL) return;
    printf("%d ", root->data);
    preorder(root->left);
    preorder(root->right);
}
void inorder(treenode* root) {
    if (root == NULL) return;
    inorder(root->left);
    printf("%d ", root->data);
    inorder(root->right);
}
void postorder(treenode* root) {
    if (root == NULL) return;
    postorder(root->left);
    postorder(root->right);
    printf("%d ", root->data);
}

int main() {
   troot= build();
    preorder(troot);
    printf("\n");
    inorder(troot);
    printf("\n");
    postorder(troot);
    printf("\n");
    return 0;
}